<?php
/**
 * Admin - View Associa Contatto a Partner - LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    16-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
    //<![CDATA[
//    var items_per_page = 10;
//    var max_elem = 5;
//    var count = 0;
//    function pageselectCallback(page_index, jq){
//	var max_elem = Math.min((page_index+1) * items_per_page, <?php echo  count( $this->contacts ) ?>);
//                
//	$('#contacts').empty();
//                
//	// Iterate through a selection of the content and build an HTML string
//	for(var i=page_index*items_per_page;i<max_elem;i++)
//	{
//	    $('#contacts').append($('#hiddenresult tr#contact_'+i+'').clone());
//	}
//		
//	// Alterna la classe delle righe
//	$("tr:even").addClass('alt');
//	$("tr:odd").removeClass('alt');
//
//	// Aggancia evento per selezionare i locali
//	$(".selectable").click(function () 
//	{
//	    $('#selected_contacts').append($('#selectedresult tr#'+$(this).attr('id')).clone()); 
//	    // Aggancia evento per deselezionare i locali
//	    $(".unselectable").click(function () 
//	    {
//		$('#selected_contacts tr#'+$(this).attr('rel')).remove(); 
//	    });
//	  
//	});
//
//	
//	return false;
//    }	
//    /** 
//     * Initialisation function for pagination
//     */
//    function initPagination() {
//	// count entries inside the hidden content
//	var num_entries = jQuery('#hiddenresult tr.result').length;
//	// Create content inside pagination element
//	$(".paginator").pagination(num_entries, {
//	    callback: pageselectCallback,
//	    next_text : 'Succ. >',
//	    prev_text : '< Prec.',
//	    num_display_entries : 0,
//	    items_per_page:items_per_page // Show only one item per page
//	});
//    }
//	     
//    $(document).ready(function()
//    {
//	initPagination();
//	    // Aggancia evento per deselezionare i locali
//	    $(".unselectable").click(function () 
//	    {
//		$('#selected_contacts tr#'+$(this).attr('rel')).remove(); 
//	    });	
//    });

    $(document).ready(function(){
	var pagination = $('#partners').pagination({
	    'targetUrl' : '/admin/ajax/list/partners',
	    'orderField' : 'partner_name',
	    'orderDir' : 'asc'
	    }, function(){
		
	    });

    });

    //]]>
</script>
<div class="info">
    <h2>Associa Contatto a Partner</h2>
    <div>Per inserire un nuovo post...</div>
    <div>I campi contrassegnati da <span class="req">*</span> sono obbligatori!</div>
</div>
    <div class="col2">
	    <div id="detailTableLeft">
	<form>
	    <ul>
		<li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none'?>">
		    <h3 id="errorMsgLbl">Si è verificato un problema durante l'invio del modulo.</h3>
		    <p id="errorMsg">
			Seleziona almeno un locale.
		    </p>
		</li>		
	    </ul>
		<!-- Container element for all the Elements that are to be paginated -->
		<table id="hiddenresult" style="display:none;">
		    <?php $i = 0;
		    foreach( $this->contacts AS $contact ) : ?>
		    <tr class="selectable" class="result" id="contact_<?php echo  $i++ ?>">
			<th title="<?php echo  $contact['contact_city'] ?> (<?php echo  $this->province[$contact['contact_prov']]['short_name'] ?>)">
			    <span><?php echo  $contact['contact_name'] ?> - <?php echo  $contact['contact_city'] ?> (<?php echo  $this->province[$contact['contact_prov']]['short_name'] ?>)</span>
			</th>
		    </tr>
		    <?php endforeach; ?>
		</table>

		<!-- Container Per gli elementi selezionati (aggiunte tag rimuovi) -->
		<table id="selectedresult" style="display:none;">
		    <?php $i = 0;
		    foreach( $this->contacts AS $contact ) : ?>
		    <tr class="result" id="contact_<?php echo $i ?>">
			<th title="<?php echo  $contact['contact_city'] ?> (<?php echo  $this->province[$contact['contact_prov']]['short_name'] ?>)">
			    <span><?php echo  $contact['contact_name'] ?> - <?php echo  $contact['contact_city'] ?> (<?php echo  $this->province[$contact['contact_prov']]['short_name'] ?>)</span>
			</th>
			<td>
			    <ul>
				<li class="complex">
				    <span class="left">
					<label>Ruolo:</label>
					<select class="field select addr" name="contact_<?php echo  $contact['contact_id'] ?>" id="contact_<?php echo  $contact['contact_id'] ?>">
					<?php foreach( $this->contact_roles AS $k => $role ) : ?>
					    <option value="<?php echo  $k ?>"><?php echo  $role ?></option>
					<?php endforeach; ?>
					</select>
				    </span>
				</li>
			    </ul>
			</td>
			<td title="Operazioni">
			    <span>
				<a class="unselectable" rel="contact_<?php echo $i?>" href="#"><img src="/images/admin/rem.png" /></a>
			    </span>
			</td>    
		    </tr>
		    <?php
		    $i++;
		    endforeach; ?>
		</table>

		<ul>
		    <li id="fo2li107" class="likert col2">
			<table cellspacing="0">
			    <caption id="title107">
				Seleziona il Contatto:
			    </caption>
			    <thead>
				<tr>
				    <td class="pagination">
					<div class="paginator"></div>
				    </td>
				</tr>
			    </thead>
			    <tbody id="contacts">
				<!-- This content will be replaced when pagination inits.-->
			    </tbody>
			    <tfoot>
				<tr>
				    <td class="pagination">
					<div class="paginator"></div>
				    </td>
				</tr>
			    </tfoot>
			</table>
		    </li>
		</ul>
	</form>
	    </div>
	<div id="detailTableRight">
    <form name="linkForm" id="linkForm" action="/admin/contatti/associa" method="post">	

	    <ul>
		<li id="fo2li107" class="likert col2">
		    <table cellspacing="0">
			<caption id="title107">
			    Clicca per Deselezionare:
			</caption>
			<tbody id="selected_contacts">
			    <!-- This content will be replaced when pagination inits.-->
			    <?php $i = 0;
			     if( is_array( $this->data['contact_roles'] ) ):
				foreach( $this->data['contact_roles'] AS $contact_role ) : 
				?>
				<tr class="result" id="contact_<?php echo  $i ?>">
				    <th title="<?php echo  $contact_role['contact_city'] ?> (<?php echo  $this->province[$contact_role['contact_prov']]['short_name'] ?>)">
					<span><?php echo  $contact_role['contact_name'] ?> - <?php echo  $contact_role['contact_city'] ?> (<?php echo  $this->province[$contact_role['contact_prov']]['short_name'] ?>)</span>
				    </th>
				    <td>
					<ul>
					    <li class="complex">
						<span class="left">
						    <label>Ruolo:</label>
						    <select class="field select addr" name="contact_<?php echo  $contact_role['contact_id'] ?>" id="contact_<?php echo  $contact_role['contact_id'] ?>">
						    <?php foreach( $this->contact_roles AS $k => $role ) : ?>
							<option value="<?php echo  $k ?>" <?php echo ($contact_role['fab_contacts_role'] == $k )? 'selected="selected"' : ''?>><?php echo  $role ?></option>
						    <?php endforeach; ?>
						    </select>
						</span>
					    </li>
					</ul>
				    </td>
				    <td title="Operazioni">
					<span>
					    <a class="unselectable" rel="contact_<?php echo $i?>" href="#"><img src="/images/admin/rem.png" /></a>
					</span>
				    </td>    
				</tr>
				<?php
				$i++;
				endforeach;
			    endif;?>  	
		    <?php $i = 0;
		    foreach( $this->contacts AS $contact ) : ?>
		    <tr class="result" id="contact_<?php echo  $i ?>">
			<th title="<?php echo  $contact['contact_city'] ?> (<?php echo  $this->province[$contact['contact_prov']]['short_name'] ?>)">
			    <span><?php echo  $contact['contact_name'] ?> - <?php echo  $contact['contact_city'] ?> (<?php echo  $this->province[$contact['contact_prov']]['short_name'] ?>)</span>
			</th>
			<td>
			    <ul>
				<li class="complex">
				    <span class="left">
					<label>Ruolo:</label>
					<select class="field select addr" name="contact_<?php echo  $contact['contact_id'] ?>" id="contact_<?php echo  $contact['contact_id'] ?>">
					<?php foreach( $this->contact_roles AS $k => $role ) : ?>
					    <option value="<?php echo  $k ?>"><?php echo  $role ?></option>
					<?php endforeach; ?>
					</select>
				    </span>
				</li>
			    </ul>
			</td>
			<td title="Operazioni">
			    <span>
				<a class="unselectable" rel="contact_<?php echo $i?>" href="#"><img src="/images/admin/rem.png" /></a>
			    </span>
			</td>    
		    </tr>
		    <?php
		    $i++;
		    endforeach; ?>				
			</tbody>
		    </table>
		</li>
	    </ul>

	</div>
    <br style="clear: both" />
    <input id="id" name="id" type="hidden" value="<?php echo $this->data['contact_id']?>" />
    <div id="formButtons">
	<button id="salva" type="submit" name="salva" value="salva" class="button positive">
	    <img src="/images/admin/add-new.png" alt="" />Salva ed Esci
	</button>
	<button id="salva" type="submit" name="salva" value="salva" class="button negative">
	    <img src="/images/admin/cross.png" alt="" />Annulla
	</button>
    </div>
    </form>
    </div>
